import config from '@/config/config.js';
import http from '@/api/http.js'

let workmanshipRequest={
    loadWorkmanship(workmanship,page=1,limit=10,callBack){
        // 获取token
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/workmanship/list?page="+page + "&limit=" + limit;
            if(workmanship){
                if(workmanship.workmanshipRouteId){
                    url += "&workmanshipRouteId=" + workmanship.workmanshipRouteId;
                }
                if(workmanship.workmanshipName){
                    url += "&workmanshipName=" + workmanship.workmanshipName;
                }
                if(workmanship.workmanshipStatus){
                    url += "&workmanshipStatus=" + workmanship.workmanshipStatus;
                }
            }
            console.log(url);
            http.get(url,callBack);
        }else{
            callBack(undefined);
        }
    },addNewWorkmanship(workmanship,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/workmanship/add";
            console.log(url);
            http.post(url,workmanship,callBack);
        }else{
            callBack(undefined);
        }
    },deleteWorkmanship(workmanshipRouteId,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/workmanship/delete?workmanshipRouteId=" + workmanshipRouteId;
            console.log(url);
            http.delete(url,callBack);
        }else{
            callBack(undefined);
        }
    },editWorkmanship(workmanship,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/workmanship/edit";
            console.log(url);
            http.post(url,workmanship,callBack);
        }else{
            callBack(undefined);
        }
    },reDelete(workmanshipRouteIds,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/workmanship/reDelete?a=1";
            if(workmanshipRouteIds){
                workmanshipRouteIds.forEach(id=>url += '&workmanshipRouteIds=' + id);
            }
            console.log(url);
            http.delete(url,callBack);
        }else{
            callBack(undefined);
        }
    },showByWorkmanshipId(workmanshipId,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.productionBaseUrl + "/workmanship/showByWorkmanshipId?workmanshipId="+workmanshipId;
            console.log(url);
            http.get(url,callBack);
        }else{
            callBack(undefined);
        }
    }
}

export default workmanshipRequest;